﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Windows.Browser;

namespace BingMapBrowser
{
	public partial class RecordView : UserControl
	{
		public RecordView()
		{
			InitializeComponent();

		}

		private void link_Click(object sender, RoutedEventArgs e)
		{
			try
			{
				LinkViewButton currentButton = sender as LinkViewButton;
				Link link = currentButton.DataContext as Link;
				if (currentButton == null)
					return;
				if (String.IsNullOrEmpty(link.Value) || link.Value.Equals("0"))
				{
					MessageBox.Show("Field " + currentButton.Content.ToString() + " is empty.");
					return;
				}
				HtmlPage.Window.Navigate(new Uri(link.Value), "_blank");
			}
			catch(Exception ex)
			{
				MessageBox.Show("Exception Occured while clicking the link.\nError Message: " + ex.Message);
			}
		}

		private void LinkViewButton_Click(object sender, RoutedEventArgs e)
		{
			var d = this.DataContext as MyEntity;
			d.OpenForm();
		}
	}

	public class LinkViewButton : Button
	{
		public string url { get; set; }

		public LinkViewButton()
			: base()
		{
		}
	}
}
